Ver Mensaje Individual
  #8
Antiguo 31 de enero de 2017, 13:46
Kuk
Administrador
Última Actividad 21.09.2026 18:24
Posts Posts: 2.500
Likes enviados Enviados: 1037
Likes recibidos Recibidos: 1207

Eslopes, gracias por la aclaración. Efectivamente, en este otro ejemplo de MF usan FACTORY y no CLASS-OBJECT:

Código COBOL:
  1.  cbl dll,thread,pgmname(longmixed),lib
  2.  Identification Division.
  3.  Class-id. Account inherits Base.
  4.  Environment Division.
  5.  Configuration section.
  6.  Repository.
  7.      Class Base    is "java.lang.Object"
  8.      Class Account is "Account".
  9. *
  10.  Identification division.
  11.  Factory.
  12.   Data division.
  13.   Working-storage section.
  14.   01 NumberOfAccounts pic 9(6) value zero.
  15. *
  16.   Procedure Division.
  17. *
  18. *    createAccount method to create a new Account
  19. *    instance, then invoke the OBJECT paragraph's init
  20. *    method on the instance to initialize its instance data:
  21.    Identification Division.
  22.    Method-id. "createAccount".
  23.    Data division.
  24.    Linkage section.
  25.    01 inAccountNumber  pic S9(6) binary.
  26.    01 outAccount object reference Account.
  27. *      Facilitate access to JNI services:
  28.      Copy JNI.
  29.    Procedure Division using by value inAccountNumber
  30.        returning outAccount.
  31. *      Establish addressability to JNI environment structure:
  32.      Set address of JNIEnv to JNIEnvPtr
  33.      Set address of JNINativeInterface to JNIEnv
  34.      Invoke Account New returning outAccount
  35.      Invoke outAccount "init" using by value inAccountNumber
  36.      Add 1 to NumberOfAccounts.
  37.    End method "createAccount".
  38. *
  39.  End Factory.
  40. *
  41.  Identification division.
  42.  Object.
  43.   Data division.
  44.   Working-storage section.
  45.   01 AccountNumber  pic 9(6).
  46.   01 AccountBalance pic S9(9) value zero.
  47. *
  48.   Procedure Division.
  49. *
  50. *    init method to initialize the account:
  51.    Identification Division.
  52.    Method-id. "init".
  53.    Data division.
  54.    Linkage section.
  55.    01 inAccountNumber pic S9(9) binary.
  56.    Procedure Division using by value inAccountNumber.
  57.      Move inAccountNumber to AccountNumber.
  58.    End method "init".
  59. *
  60. *    getBalance method to return the account balance:
  61.    Identification Division.
  62.    Method-id. "getBalance".
  63.    Data division.
  64.    Linkage section.
  65.    01 outBalance pic S9(9) binary.
  66.    Procedure Division returning outBalance.
  67.      Move AccountBalance to outBalance.
  68.    End method "getBalance".
  69. *
  70. *    credit method to deposit to the account:
  71.    Identification Division.
  72.    Method-id. "credit".
  73.    Data division.
  74.    Linkage section.
  75.    01 inCredit   pic S9(9) binary.
  76.    Procedure Division using by value inCredit.
  77.      Add inCredit to AccountBalance.
  78.    End method "credit".
  79. *
  80. *    debit method to withdraw from the account:
  81.    Identification Division.
  82.    Method-id. "debit".
  83.    Data division.
  84.    Linkage section.
  85.    01 inDebit    pic S9(9) binary.
  86.    Procedure Division using by value inDebit.
  87.      Subtract inDebit from AccountBalance.
  88.    End method "debit".
  89. *
  90. *    print method to display formatted account number and balance:
  91.    Identification Division.
  92.    Method-id. "print".
  93.    Data division.
  94.    Local-storage section.
  95.    01 PrintableAccountNumber  pic ZZZZZZ999999.
  96.    01 PrintableAccountBalance pic $$$$,$$$,$$9CR.
  97.    Procedure Division.
  98.      Move AccountNumber  to PrintableAccountNumber
  99.      Move AccountBalance to PrintableAccountBalance
  100.      Display " Account: " PrintableAccountNumber
  101.      Display " Balance: " PrintableAccountBalance.
  102.    End method "print".
  103. *
  104.  End Object.
  105. *
  106.  End class Account.

MF es muy permisivo, le pasas una poesía y lo compila también. Demasiado liberal, en mi opinión.

CONCLUSIÓN: Class-Object y Factory son exactamente lo mismo, dependiendo del compilador que se use. En Fujitsu hay que siempre utilizar FACTORY, en MF se puede utilizar ambos.

Eslopes, corrígeme si algo no es correcto.



NORMAS DEL FORO - para garantizar el buen funcionamiento del Foro.
¿Te han ayudado? NO TE OLVIDES de darle a
¿Quieres dirigirte a alguien en tu post? Notifícale haciendo clic en su Nick
Kuk is offline   Responder Con Cita