Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

help me to cosmetize my code

hi experts,

the following is code given to me as assignment.iam done with my code.but have no idea how to cosmetize the code.plz look into it and let me know.

*-----TABLES DECLARATION

TABLES : KNA1, "Customer Master

  • vbak, "Sales Document Header

VBAP, "Sales Document Item

SSCRFIELDS. "Screen Field Table

&----


&

& D A T A D E C L A R A T I O N &

&----


&

DATA : BEGIN OF IT_KNA1 OCCURS 0,

KUNNR TYPE KNA1-KUNNR, "Customer Number

LAND1 TYPE KNA1-LAND1, "Country Key

NAME1 TYPE KNA1-NAME1, "Name

ORT01 TYPE KNA1-ORT01, "City

END OF IT_KNA1.

DATA : BEGIN OF IT_KNA2 OCCURS 0,

KUNNR TYPE KNA1-KUNNR, "Customer Number

LAND1 TYPE KNA1-LAND1, "Country Key

NAME1 TYPE KNA1-NAME1, "Name

ORT01 TYPE KNA1-ORT01, "City

END OF IT_KNA2.

DATA: BEGIN OF IT_VBAK OCCURS 0,

VBELN TYPE VBAK-VBELN, "Sales Document

ERDAT TYPE VBAK-ERDAT, "Date

ERNAM TYPE VBAK-ERNAM, "Name of Person

AUART TYPE VBAK-AUART, "Sales Document Type

END OF IT_VBAK.

DATA: BEGIN OF IT_VBAP OCCURS 0,

VBELN TYPE VBAP-VBELN, "Sales Document

POSNR TYPE VBAP-POSNR, "Sales Document Item

MATNR TYPE VBAP-MATNR, "Material Number

MATKL TYPE VBAP-MATKL, "Material group

END OF IT_VBAP.

DATA: V_COUNT TYPE INT4, "Current Row Index

V_LINE LIKE SY-LISEL, "Contents of selected line

V_KUNNR LIKE KNA1-KUNNR.

&----


&

& S E L E C T I O N S C R E E N &

&----


&

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

SELECTION-SCREEN BEGIN OF LINE.

PARAMETERS : RB1 RADIOBUTTON GROUP G1 DEFAULT 'X'.

SELECTION-SCREEN COMMENT 5(20) TEXT-002 FOR FIELD RB1.

SELECTION-SCREEN END OF LINE.

SELECT-OPTIONS : SO_KUNNR FOR KNA1-KUNNR OBLIGATORY.

PARAMETERS : P_HITS(3) TYPE C.

SELECTION-SCREEN BEGIN OF LINE.

PARAMETERS : RB2 RADIOBUTTON GROUP G1.

SELECTION-SCREEN COMMENT 5(20) TEXT-003 FOR FIELD RB2.

SELECTION-SCREEN END OF LINE.

PARAMETERS : P_FILE LIKE RLGRAP-FILENAME DEFAULT 'c:\test'.

SELECTION-SCREEN PUSHBUTTON /33(10) CUSTL USER-COMMAND PUSH1.

SELECTION-SCREEN PUSHBUTTON 58(10) CUSTD USER-COMMAND PUSH2.

SELECTION-SCREEN END OF BLOCK B1.

&----


&

& I N I T I A L I Z A T I O N &

&----


&

INITIALIZATION.

MOVE 'LOAD' TO CUSTL.

MOVE 'DISP' TO CUSTD.

&----


&

& A T L I N E S E L E C T I O N &

&----


&

AT SELECTION-SCREEN.

PERFORM VALIDATE_KUNNR.

&----


&

& A T S E L E C T I O N S C R E E N O N V A L U E-R E Q U E S T &

&----


&

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

DYNPRO_NUMBER = SYST-DYNNR

FIELD_NAME = ' '

IMPORTING

FILE_NAME = P_FILE.

&----


&

& S T A R T O F S E L E C T I O N &

&----


&

START-OF-SELECTION.

PERFORM CUST_DETAILS.

&----


&

& S T A R T O F S E L E C T I O N &

&----


&

TOP-OF-PAGE.

FORMAT COLOR 3 INTENSIFIED OFF.

WRITE :/02(25) SY-REPID.

WRITE : 39(15) 'Page'(010), SY-PAGNO.

FORMAT COLOR OFF.

FORMAT COLOR 6 INTENSIFIED OFF.

FORMAT COLOR COL_HEADING.

ULINE AT :/1(60).

WRITE: /1 SY-VLINE,

2 'Cust Number'(000),

14 SY-VLINE,

16 'Country'(007),

25 SY-VLINE,

26 'City'(008),

42 SY-VLINE,

43 'Region'(009),

60 SY-VLINE.

ULINE AT :/1(60).

FORMAT COLOR COL_HEADING OFF.

&----


&

& T O P O F P A G E D U R I N G L I N E S E L E C T I O N &

&----


&

TOP-OF-PAGE DURING LINE-SELECTION.

IF SY-LSIND EQ 1 OR SY-UCOMM EQ 'VBAK'.

FORMAT COLOR COL_HEADING.

ULINE AT :/1(60).

WRITE : /1 SY-VLINE,

2 'Docu No.'(011),

14 SY-VLINE,

16 'Date'(012),

26 SY-VLINE,

27 'Name'(013),

42 SY-VLINE,

43 'DType'(014),

60 SY-VLINE.

ULINE AT :/1(60).

ELSEIF SY-LSIND EQ 2 OR SY-UCOMM EQ 'VBAK'.

SET PF-STATUS SPACE.

ULINE AT :/1(60).

WRITE : /1 SY-VLINE,

2 'Docu No.'(015),

14 SY-VLINE,

16 'Sales Item'(016),

25 SY-VLINE,

26 'Mat No'(017),

42 SY-VLINE,

43 VBAP-MATKL,

50 'Mat Grp'(018),

60 SY-VLINE.

ULINE AT :/1(60).

ENDIF.

&----


&

& AT USER-COMMAND &

&----


&

AT USER-COMMAND.

CASE SY-UCOMM.

WHEN 'VBAK'.

PERFORM SALES_ITEM.

WHEN 'DELIVERY'.

CLEAR IT_VBAK-VBELN.

GET CURSOR VALUE IT_VBAK-VBELN.

SET PARAMETER ID 'AUN' FIELD IT_VBAK-VBELN.

CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.

WHEN 'DISP'.

PERFORM DISPLAY_BASIC.

ENDCASE.

&----


&

& AT LINE SELECTION &

&----


&

AT LINE-SELECTION.

IF SY-LSIND = 1.

SET PF-STATUS 'DDDD'.

PERFORM SALES_HEADER.

ELSEIF SY-LSIND = 2.

CASE SY-UCOMM.

WHEN 'PICK'.

SET PF-STATUS SPACE.

PERFORM SALES_ITEM.

WHEN 'DELIVERY'.

CLEAR IT_VBAK-VBELN.

GET CURSOR VALUE IT_VBAK-VBELN.

SET PARAMETER ID 'AUN' FIELD IT_VBAK-VBELN.

CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.

WHEN 'DISP'.

PERFORM DISPLAY_BASIC.

ENDCASE.

  • PERFORM sales_item.

ENDIF.

&----


&

& AT USER-COMMAND &

&----


&

AT USER-COMMAND.

CASE SY-UCOMM.

WHEN 'VBAK'.

PERFORM SALES_ITEM.

WHEN 'DELIVERY'.

CLEAR IT_VBAK-VBELN.

GET CURSOR VALUE IT_VBAK-VBELN.

SET PARAMETER ID 'AUN' FIELD IT_VBAK-VBELN.

CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.

WHEN 'DISP'.

PERFORM DISPLAY_BASIC.

ENDCASE.

&----


&

& Form CUST_DETAILS &

&----


&

FORM CUST_DETAILS .

SELECT KUNNR

LAND1

NAME1

ORT01

FROM KNA1

INTO TABLE IT_KNA1

WHERE KUNNR IN SO_KUNNR.

IF SY-SUBRC <> 0.

MESSAGE 'SELECT VALID CUST NO' TYPE 'I'.

ELSE.

LOOP AT IT_KNA1.

  • v_count = v_count + 1.

IF SY-TABIX < P_HITS.

  • IF v_count <= p_hits.

MOVE IT_KNA1 TO IT_KNA2.

APPEND IT_KNA2.

ELSE.

EXIT.

ENDIF.

ENDLOOP.

ENDIF.

IF NOT IT_KNA2[] IS INITIAL.

LOOP AT IT_KNA2.

WRITE : /1 SY-VLINE,

2 IT_KNA2-KUNNR,

14 SY-VLINE,

16 IT_KNA2-LAND1,

25 SY-VLINE,

26 IT_KNA2-NAME1,

42 SY-VLINE,

43 IT_KNA2-ORT01,

60 SY-VLINE.

ULINE AT :/1(60).

ENDLOOP.

ENDIF.

ENDFORM. " CUST_DETAILS

*&----


**& Form load_file

*&----


*form load_file .

*

*endform. " load_file

*&----


**& Form disp_file

*&----


*form disp_file .

*

*endform. " disp_file

&----


*& Form VALIDATE_KUNNR

&----


FORM VALIDATE_KUNNR .

SELECT SINGLE KUNNR

FROM KNA1

INTO KNA1

WHERE KUNNR = SO_KUNNR.

ENDFORM. " VALIDATE_KUNNR

&----


*& Form SALES_HEADER

&----


FORM SALES_HEADER .

DATA : V_KNA1(13).

V_KNA1 = 'IT_KNA2-KUNNR'.

*get cursor line sy-lilli value v_line

CLEAR V_KUNNR.

GET CURSOR FIELD V_KNA1 VALUE V_KUNNR.

  • v_kunnr = v_line+1(10).

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = V_KUNNR

IMPORTING

OUTPUT = V_KUNNR.

SELECT VBELN

ERDAT

ERNAM

AUART

FROM VBAK

INTO TABLE IT_VBAK

WHERE KUNNR = V_KUNNR.

IF SY-SUBRC = 0.

LOOP AT IT_VBAK.

WRITE : /1 SY-VLINE,

2 IT_VBAK-VBELN,

14 SY-VLINE,

16 IT_VBAK-ERDAT,

26 SY-VLINE,

27 IT_VBAK-ERNAM,

42 SY-VLINE,

43 IT_VBAK-AUART,

60 SY-VLINE.

ULINE AT :/1(60).

ENDLOOP.

ENDIF.

ENDFORM. " SALES_HEADER

&----


*& Form SALES_ITEM

&----


FORM SALES_ITEM .

DATA : V_VBELN(13).

V_VBELN = 'IT_VBAK-VBELN'.

CLEAR IT_VBAK-VBELN.

GET CURSOR FIELD V_VBELN VALUE IT_VBAK-VBELN.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = IT_VBAK-VBELN

IMPORTING

OUTPUT = IT_VBAK-VBELN.

SELECT VBELN

POSNR

MATNR

MATKL

FROM VBAP

INTO TABLE IT_VBAP

WHERE VBELN = IT_VBAK-VBELN.

LOOP AT IT_VBAP .

WRITE : /1 SY-VLINE,

2 IT_VBAP-VBELN,

14 SY-VLINE,

16 IT_VBAP-POSNR,

25 SY-VLINE,

26 IT_VBAP-MATNR,

42 SY-VLINE,

43 IT_VBAP-MATKL,

60 SY-VLINE.

ULINE AT :/1(60).

ENDLOOP.

ENDFORM. " SALES_ITEM

&----


*& Form DISP_DOCU

&----


FORM DISPLAY_BASIC .

LOOP AT IT_KNA1 INTO IT_KNA1.

FORMAT HOTSPOT ON.

WRITE : /03 IT_KNA1-KUNNR,

24 IT_KNA1-NAME1.

HIDE IT_KNA1-KUNNR.

ENDLOOP.

Tags:
Former Member

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question