SAP ABAP - Sample Program To Fetch Company Code Of All The Vendors.
This sample program can be used to fetch company codes of all the vendors.
REPORT ztest_comp_code_of_vendor.
DATA:BEGIN OF fieldnames OCCURS 0,
field(75),
END OF fieldnames.
DATA: BEGIN OF it_final OCCURS 0,
altkn TYPE altkn,
lifnr TYPE lifnr,
bukrs TYPE bukrs,
name1 TYPE name1_gp,
name2 TYPE name2_gp,
END OF it_final.
DATA: BEGIN OF it_lfa1 OCCURS 0,
lifnr TYPE lifnr,
name1 TYPE name1_gp,
name2 TYPE name2_gp,
END OF it_lfa1.
DATA: BEGIN OF it_lfb1 OCCURS 0,
lifnr TYPE lifnr,
bukrs TYPE bukrs,
altkn TYPE altkn,
END OF it_lfb1.
DATA:file TYPE string.
DATA: vendor TYPE lifnr.
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETER : pfname LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN : END OF BLOCK b1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR pfname.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
static = 'X'
CHANGING
file_name = pfname.
START-OF-SELECTION.
SELECT lifnr
name1
name2
INTO TABLE it_lfa1
FROM lfa1.
SELECT lifnr
bukrs
altkn
INTO TABLE it_lfb1
FROM lfb1.
SORT it_lfa1 BY lifnr.
SORT it_lfb1 BY lifnr.
LOOP AT it_lfa1.
READ TABLE it_lfb1 WITH KEY lifnr = it_lfa1-lifnr.
IF sy-subrc = 0.
CLEAR vendor.
vendor = it_lfb1-lifnr.
LOOP AT it_lfb1 FROM sy-tabix.
IF it_lfb1-lifnr <> vendor.
EXIT.
ENDIF.
CLEAR it_final.
it_final-lifnr = it_lfa1-lifnr .
it_final-name1 = it_lfa1-name1 .
it_final-name2 = it_lfa1-name2 .
it_final-altkn = it_lfb1-altkn .
it_final-bukrs = it_lfb1-bukrs .
APPEND it_final.
ENDLOOP.
ENDIF.
ENDLOOP.
fieldnames-field = 'Old vendor'.
APPEND fieldnames.
CLEAR fieldnames.
fieldnames-field = 'New vendor'.
APPEND fieldnames.
CLEAR fieldnames.
fieldnames-field = 'Company code'.
APPEND fieldnames.
CLEAR fieldnames.
fieldnames-field = 'Name 1'.
APPEND fieldnames.
CLEAR fieldnames.
fieldnames-field = 'Name 2'.
APPEND fieldnames.
CLEAR fieldnames.
file = pfname.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = file
filetype = 'DAT'
TABLES
data_tab = it_final
fieldnames = fieldnames
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
IF sy-subrc = 0.
MESSAGE : 'Downloaded successfully' TYPE 'I'.
ENDIF.
MORE PROGRAMS ON REPORT PROGRAMMING:
- Setting Default Values In Selection Screen.
- Programming On Buttons In A Screen.
- Create A Screen With Two TABSTRIPS For A Report Program.
- On Using HOTSPOT Keyword In A Report Program.
- Demonstrate Tabstrips & Subscreens In Selection Screen.
- ...Back To Index On Report Programming.
Your suggestions and comments are welcome in this section.
Please mail all your contributions to administrator@abapmadeeasy.com We request you to mention your Name, Designation, Experience & Organization you are working for. Your posts will be verified and posted in this site with your name.
REPORT ztest_comp_code_of_vendor.
DATA:BEGIN OF fieldnames OCCURS 0,
field(75),
END OF fieldnames.
DATA: BEGIN OF it_final OCCURS 0,
altkn TYPE altkn,
lifnr TYPE lifnr,
bukrs TYPE bukrs,
name1 TYPE name1_gp,
name2 TYPE name2_gp,
END OF it_final.
DATA: BEGIN OF it_lfa1 OCCURS 0,
lifnr TYPE lifnr,
name1 TYPE name1_gp,
name2 TYPE name2_gp,
END OF it_lfa1.
DATA: BEGIN OF it_lfb1 OCCURS 0,
lifnr TYPE lifnr,
bukrs TYPE bukrs,
altkn TYPE altkn,
END OF it_lfb1.
DATA:file TYPE string.
DATA: vendor TYPE lifnr.
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETER : pfname LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN : END OF BLOCK b1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR pfname.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
static = 'X'
CHANGING
file_name = pfname.
START-OF-SELECTION.
SELECT lifnr
name1
name2
INTO TABLE it_lfa1
FROM lfa1.
SELECT lifnr
bukrs
altkn
INTO TABLE it_lfb1
FROM lfb1.
SORT it_lfa1 BY lifnr.
SORT it_lfb1 BY lifnr.
LOOP AT it_lfa1.
READ TABLE it_lfb1 WITH KEY lifnr = it_lfa1-lifnr.
IF sy-subrc = 0.
CLEAR vendor.
vendor = it_lfb1-lifnr.
LOOP AT it_lfb1 FROM sy-tabix.
IF it_lfb1-lifnr <> vendor.
EXIT.
ENDIF.
CLEAR it_final.
it_final-lifnr = it_lfa1-lifnr .
it_final-name1 = it_lfa1-name1 .
it_final-name2 = it_lfa1-name2 .
it_final-altkn = it_lfb1-altkn .
it_final-bukrs = it_lfb1-bukrs .
APPEND it_final.
ENDLOOP.
ENDIF.
ENDLOOP.
fieldnames-field = 'Old vendor'.
APPEND fieldnames.
CLEAR fieldnames.
fieldnames-field = 'New vendor'.
APPEND fieldnames.
CLEAR fieldnames.
fieldnames-field = 'Company code'.
APPEND fieldnames.
CLEAR fieldnames.
fieldnames-field = 'Name 1'.
APPEND fieldnames.
CLEAR fieldnames.
fieldnames-field = 'Name 2'.
APPEND fieldnames.
CLEAR fieldnames.
file = pfname.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = file
filetype = 'DAT'
TABLES
data_tab = it_final
fieldnames = fieldnames
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
IF sy-subrc = 0.
MESSAGE : 'Downloaded successfully' TYPE 'I'.
ENDIF.
MORE PROGRAMS ON REPORT PROGRAMMING:
- Setting Default Values In Selection Screen.
- Programming On Buttons In A Screen.
- Create A Screen With Two TABSTRIPS For A Report Program.
- On Using HOTSPOT Keyword In A Report Program.
- Demonstrate Tabstrips & Subscreens In Selection Screen.
- ...Back To Index On Report Programming.
Your suggestions and comments are welcome in this section.
Please mail all your contributions to administrator@abapmadeeasy.com We request you to mention your Name, Designation, Experience & Organization you are working for. Your posts will be verified and posted in this site with your name.