CLASSICAL REPORT IN SAP ABAP
*&---------------------------------------------------------------------*
*& Report ZSIBLING_AGE_DIFF
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZSIBLING_AGE_DIFF.
TYPES: BEGIN OF TY_FATHER,
FATHERID TYPE ZFATHERID,
FATHERNAME TYPE ZFATHERNAME,
FATHERDOB TYPE ZFATHERDOB,
END OF TY_FATHER.
TYPES: BEGIN OF TY_MOTHER,
MOTHERID TYPE ZMOTHERID,
HUSBANDID TYPE ZFATHERID,
MOTHERNAME TYPE ZMOTHERNAME,
MOTHERDOB TYPE ZMOTHERDOB,
END OF TY_MOTHER.
TYPES: BEGIN OF TY_CHILDREN,
CHILDID TYPE ZCHILDID,
FATHERID TYPE ZFATHERID,
MOTHERID TYPE ZMOTHERID,
CHILDNAME TYPE ZCHILDNAME,
CHILDDOB TYPE ZCHILDDOB,
CHILDGENDER TYPE ZCHILDGENDER,
END OF TY_CHILDREN.
TYPES: BEGIN OF TY_CHILD_AGE,
FATHERNAME TYPE ZFATHERNAME,
CHILDNAME TYPE ZCHILDNAME,
CHILDID TYPE ZCHILDID,
YEARS TYPE NUM2,
END OF TY_CHILD_AGE.
TYPES: BEGIN OF TY_FINAL,
CHILDID TYPE ZCHILDID,
FATHERNAME TYPE ZFATHERNAME,
CHILDNAME TYPE ZCHILDNAME,
CHILDAGE TYPE I,
FIRSTDIFF TYPE I,
SECONDDIFF TYPE I,
THIRDDIFF TYPE I,
END OF TY_FINAL.
DATA: IT_FINAL TYPE TABLE OF TY_FINAL,
WA_FINAL TYPE TY_FINAL.
DATA: IT_CHILD_AGE1 TYPE TABLE OF TY_CHILD_AGE,
WA_CHILD_AGE1 TYPE TY_CHILD_AGE,
LINE_COUNT TYPE I,
AGE TYPE I,
AGE1 TYPE I,
AGE_DIFF TYPE I.
DATA: IT_CHILD_AGE TYPE TABLE OF TY_CHILD_AGE,
WA_CHILD_AGE TYPE TY_CHILD_AGE.
DATA: IT_FATHER TYPE TABLE OF TY_FATHER,
WA_FATHER TYPE TY_FATHER.
DATA: IT_MOTHER TYPE TABLE OF TY_MOTHER,
WA_MOTHER TYPE TY_MOTHER.
DATA: IT_CHILDREN TYPE TABLE OF TY_CHILDREN,
WA_CHILDREN TYPE TY_CHILDREN.
"DATA: S_FATHERID TYPE ZFATHER-FATHERID.
DATA: DAYS TYPE NUM2,
MONTHS TYPE NUM2,
YEARS TYPE NUM2.
DATA: V_LINES TYPE I.
SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS: P_FID TYPE ZFATHER-FATHERID.
SELECTION-SCREEN: END OF BLOCK B1.
START-OF-SELECTION.
SELECT CHILDID FATHERID MOTHERID CHILDNAME CHILDDOB CHILDGENDER FROM ZCHILDREAN INTO TABLE IT_CHILDREN
WHERE FATHERID EQ P_FID.
IF SY-SUBRC EQ 0.
SORT IT_CHILDREN BY CHILDID.
SELECT FATHERID FATHERNAME FATHERDOB FROM ZFATHER INTO TABLE IT_FATHER FOR ALL ENTRIES IN IT_CHILDREN
WHERE FATHERID = IT_CHILDREN-FATHERID.
ENDIF.
END-OF-SELECTION.
LOOP AT IT_CHILDREN INTO WA_CHILDREN.
READ TABLE IT_FATHER INTO WA_FATHER WITH KEY FATHERID = WA_CHILDREN-FATHERID BINARY SEARCH.
WA_CHILD_AGE-FATHERNAME = WA_FATHER-FATHERNAME.
WA_CHILD_AGE-CHILDNAME = WA_CHILDREN-CHILDNAME.
WA_CHILD_AGE-CHILDID = WA_CHILDREN-CHILDID.
CALL FUNCTION 'HRCM_TIME_PERIOD_CALCULATE'
EXPORTING
BEGDA = WA_CHILDREN-CHILDDOB
ENDDA = SY-DATUM
IMPORTING
NOYRS = YEARS
NOMNS = MONTHS
NODYS = DAYS
EXCEPTIONS
INVALID_DATES = 1
OVERFLOW = 2
OTHERS = 3.
WA_CHILD_AGE-YEARS = YEARS.
APPEND WA_CHILD_AGE TO IT_CHILD_AGE.
CLEAR WA_CHILD_AGE.
ENDLOOP.
IT_CHILD_AGE1[] = IT_CHILD_AGE.
DESCRIBE TABLE IT_CHILD_AGE LINES V_LINES.
WRITE:/ 'TOTAL CHILD:-',V_LINES.
ULINE.
WRITE:/ 'FATHER NAME',
20 'CHILD NAME',
40 'CHILD AGE',
60 'FIRST DIFF',
80 'SECOND DIFF',
100 'THIRD DIFF'.
ULINE.
LOOP AT IT_CHILD_AGE INTO WA_CHILD_AGE.
WA_FINAL-CHILDID = WA_CHILD_AGE-CHILDID.
WA_FINAL-FATHERNAME = WA_CHILD_AGE-FATHERNAME.
WA_FINAL-CHILDNAME = WA_CHILD_AGE-CHILDNAME.
WA_FINAL-CHILDAGE = WA_CHILD_AGE-YEARS.
* WA_FINAL-FIRSTDIFF = ''.
* WA_FINAL-SECONDDIFF = ''.
* WA_FINAL-THIRDDIFF = ''.
APPEND WA_FINAL TO IT_FINAL.
CLEAR WA_FINAL.
ENDLOOP.
LOOP AT IT_CHILD_AGE INTO WA_CHILD_AGE.
* WRITE:/ WA_CHILD_AGE-FATHERNAME,
* 20 WA_CHILD_AGE-CHILDNAME,
* 40 WA_CHILD_AGE-YEARS.
WA_FINAL-FATHERNAME = WA_CHILD_AGE-FATHERNAME.
WA_FINAL-CHILDNAME = WA_CHILD_AGE-CHILDNAME.
WA_FINAL-CHILDAGE = WA_CHILD_AGE-YEARS.
LINE_COUNT = 1.
LOOP AT IT_CHILD_AGE1 INTO WA_CHILD_AGE1.
IF WA_CHILD_AGE-CHILDID NE WA_CHILD_AGE1-CHILDID.
IF WA_CHILD_AGE-YEARS GT WA_CHILD_AGE1-YEARS.
AGE = WA_CHILD_AGE-YEARS.
AGE1 = WA_CHILD_AGE1-YEARS.
AGE_DIFF = AGE - AGE1.
IF LINE_COUNT EQ 1.
WA_FINAL-FIRSTDIFF = AGE_DIFF.
MODIFY IT_FINAL FROM WA_FINAL TRANSPORTING FIRSTDIFF WHERE CHILDID = WA_CHILD_AGE-CHILDID.
ENDIF.
IF LINE_COUNT EQ 2.
WA_FINAL-SECONDDIFF = AGE_DIFF.
MODIFY IT_FINAL FROM WA_FINAL TRANSPORTING SECONDDIFF WHERE CHILDID = WA_CHILD_AGE-CHILDID.
ENDIF.
IF LINE_COUNT EQ 3.
WA_FINAL-THIRDDIFF = AGE_DIFF.
MODIFY IT_FINAL FROM WA_FINAL TRANSPORTING THIRDDIFF WHERE CHILDID = WA_CHILD_AGE-CHILDID.
ENDIF.
"WRITE:/ AGE_DIFF.
ELSE.
AGE = WA_CHILD_AGE1-YEARS.
AGE1 = WA_CHILD_AGE-YEARS.
AGE_DIFF = AGE - AGE1.
IF LINE_COUNT EQ 1.
WA_FINAL-FIRSTDIFF = AGE_DIFF.
MODIFY IT_FINAL FROM WA_FINAL TRANSPORTING FIRSTDIFF WHERE CHILDID = WA_CHILD_AGE-CHILDID.
ENDIF.
IF LINE_COUNT EQ 2.
WA_FINAL-SECONDDIFF = AGE_DIFF.
MODIFY IT_FINAL FROM WA_FINAL TRANSPORTING SECONDDIFF WHERE CHILDID = WA_CHILD_AGE-CHILDID.
ENDIF.
IF LINE_COUNT EQ 3.
WA_FINAL-THIRDDIFF = AGE_DIFF.
MODIFY IT_FINAL FROM WA_FINAL TRANSPORTING THIRDDIFF WHERE CHILDID = WA_CHILD_AGE-CHILDID.
ENDIF.
"WRITE:/ AGE_DIFF.
ENDIF.
LINE_COUNT = LINE_COUNT + 1.
ENDIF.
* APPEND WA_FINAL TO IT_FINAL.
* CLEAR WA_FINAL.
ENDLOOP.
ENDLOOP.
LOOP AT IT_FINAL INTO WA_FINAL.
WRITE:/ WA_FINAL-FATHERNAME,
20 WA_FINAL-CHILDNAME,
40 WA_FINAL-CHILDAGE,
60 WA_FINAL-FIRSTDIFF,
80 WA_FINAL-SECONDDIFF,
100 WA_FINAL-THIRDDIFF.
ENDLOOP.
*
*TYPES: BEGIN OF TY_CHILD_AGE,
* FATHERNAME TYPE ZFATHERNAME,
* CHILDNAME TYPE ZCHILDNAME,
* CHILDID TYPE ZCHILDID,
* YEARS TYPE NUM2,
* END OF TY_CHILD_AGE.
*DATA: IT_CHILD_AGE TYPE TABLE OF TY_CHILD_AGE,
* WA_CHILD_AGE TYPE TY_CHILD_AGE.