You are on page 1of 6

*&---------------------------------------------------------------------*

*& Report ZALI_OUTBOUND_INTERFACE


*&
*&---------------------------------------------------------------------*
*&
Author : Ali Mohammed
*
*&
Title : Outbound Interafce-on Functional spec
*
*&
Purpose: This Interface is used to create 2 files in the
*&
Application server level
*&
*& Transport:INDK901006
*& Version :V1
*&---------------------------------------------------------------------*
*& Version
Transport
Purpose
*&---------------------------------------------------------------------*
*& V2
INDK901007
Addition of new fields
*&---------------------------------------------------------------------*
REPORT ZALI_OUTBOUND_INTERFACE.

*&---------------------------------------------------------------------*
*& Structure Declaration
*&---------------------------------------------------------------------*
* Structure Declaration for Vendor Master (General Section) and Vendor Master (C
ompany Code)
TYPES: BEGIN OF TY_LFA1_LFB1,
LIFNR TYPE LIFNR,
" Account Number of Vendor or Creditor
NAME1 TYPE NAME1_GP,
" Name 1
NAME2 TYPE NAME2_GP,
" Name 2
ADRNR TYPE ADRNR,
" Address
BUKRS TYPE BUKRS,
" Company Code
ZAHLS TYPE DZAHLS,
" Block key for payment
END OF TY_LFA1_LFB1,
* Structure Declaration for Addresses
BEGIN OF TY_ADRC,
ADDRNUMBER TYPE AD_ADDRNUM,
SORT1 TYPE AD_SORT1,
SORT2 TYPE AD_SORT2,
END OF TY_ADRC,
* Structure Declaration for Output
BEGIN OF TY_OUTPUT,
SORT2 TYPE AD_SORT2,
LIFNR TYPE LIFNR,
NAME1 TYPE NAME1_GP,
NAME2 TYPE NAME2_GP,
ZAHLS TYPE DZAHLS,
SORT1 TYPE AD_SORT1,
END OF TY_OUTPUT.

" Address number


" Serach Term 1
" Search Term 2

"
"
"
"
"
"

Search Term 2
Account Number of Vendor or Creditor
Name 1
Name 2
Block key for payment
Serach Term 1

*&---------------------------------------------------------------------*
*& Internal table declaration
*&---------------------------------------------------------------------*
* Internal table declaration for Vendor Master and Company code

DATA : T_LFA1_LFB1 TYPE STANDARD TABLE OF TY_LFA1_LFB1 INITIAL SIZE 0,


* Internal table declaration for Addresses
T_ADRC TYPE STANDARD TABLE OF TY_ADRC INITIAL SIZE 0,
* Internal table declaration for Toys refering to ty_output
s we need to create 2 files for toy and vit

" Beco

T_TOYS TYPE STANDARD TABLE OF TY_OUTPUT INITIAL SIZE 0,


* Internal table declaration for Toys refering to ty_output
T_VIT TYPE STANDARD TABLE OF TY_OUTPUT INITIAL SIZE 0.
*&---------------------------------------------------------------------*
*& Work area declaration
*&---------------------------------------------------------------------*
DATA: W_LFA1_LFB1 TYPE TY_LFA1_LFB1,
" here we need only 3 W.A
W_ADRC TYPE TY_ADRC,
W_OUTPUT TYPE TY_OUTPUT.
it refering to output structure

" 1 W.A area for both toys and v

*&---------------------------------------------------------------------*
*& Global Variable declaration
*&---------------------------------------------------------------------*
DATA : G_KTOKK TYPE LFA1-KTOKK,
G_BUKRS TYPE LFB1-BUKRS.

" Vendor account group


" Company Code

*&---------------------------------------------------------------------*
*& Selection screen declaration
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
SELECT-OPTIONS: S_KTOKK FOR G_KTOKK,
S_BUKRS FOR G_BUKRS NO INTERVALS OBLIGATORY.
PARAMETERS : P_TOYS TYPE FILENAME,
" P_stands for parameter-T
his is for toys
P_VIT TYPE FILENAME.
" This is for vit
SELECTION-SCREEN END OF BLOCK B1.
*&---------------------------------------------------------------------*
*& Initialization
*&---------------------------------------------------------------------*
INITIALIZATION.
* Clear Work areas
CLEAR : W_LFA1_LFB1,
W_ADRC,
W_OUTPUT.
* Refresh Internal tables

REFRESH : T_LFA1_LFB1,
T_ADRC,
T_TOYS,
T_VIT.

*&---------------------------------------------------------------------*
*& At selection screen declaration
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN.
* Validating the account group(Number)
PERFORM SUB_VALIDATE_LIFNR.
* Validating the Company Code
PERFORM SUB_VALIDATE_BUKRS.
*&---------------------------------------------------------------------*
*& Start of selection declaration
*&---------------------------------------------------------------------*
START-OF-SELECTION.
* Get LFA1 and LFB1 data
PERFORM SUB_GET_LFA1_LFB1.
* Get ADRC table data
PERFORM SUB_GET_ADRC.
* Populate the output
PERFORM SUB_POP_OUTPUT.
* To send the file in Appliaction Level
PERFORM SUB_SEND_DATA.

*&---------------------------------------------------------------------*
*&
Form SUB_VALIDATE_LIFNR
*&---------------------------------------------------------------------*
*
This subroutine is used to validate Account Group
*----------------------------------------------------------------------*
FORM SUB_VALIDATE_LIFNR .
DATA : L_KTOKK TYPE KTOKK.
SELECT SINGLE KTOKK
FROM T077K
INTO L_KTOKK
WHERE KTOKK IN S_KTOKK.

IF SY-SUBRC <> 0.
MESSAGE E002(ZALIBATCH32) WITH 'Invalid Account Group'.
ENDIF.
ENDFORM.
" SUB_VALIDATE_LIFNR
*&---------------------------------------------------------------------*
*&
Form SUB_VALIDATE_BUKRS
*&---------------------------------------------------------------------*
*
This subroutine is used to validate Company Code
*----------------------------------------------------------------------*
FORM SUB_VALIDATE_BUKRS .
DATA : L_BUKRS TYPE BUKRS.
SELECT SINGLE BUKRS
FROM T001
INTO L_BUKRS
WHERE BUKRS IN S_BUKRS.
IF SY-SUBRC <> 0.
MESSAGE E002(ZALIBATCH32) WITH 'Invalid Company Code'.
ENDIF.
ENDFORM.

" SUB_VALIDATE_BUKRS

*&---------------------------------------------------------------------*
*&
Form sub_get_lfa1_lfb1
*&---------------------------------------------------------------------*
*
This subroutine is used to get the data of LFA1(Vendor Master) and LFB1(
Company Code)
*
using inner joins
*----------------------------------------------------------------------*
FORM SUB_GET_LFA1_LFB1 .
SELECT A~LIFNR
A~NAME1
A~NAME2
A~ADRNR
B~BUKRS
B~ZAHLS
INTO TABLE T_LFA1_LFB1
FROM LFA1 AS A
INNER JOIN LFB1 AS B
ON A~LIFNR = B~LIFNR
WHERE A~KTOKK IN S_KTOKK AND
B~BUKRS IN S_BUKRS.
IF SY-SUBRC <> 0.
MESSAGE I002(ZALIBATCH32) WITH 'Data not maintained for given range'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM.
" sub_get_lfa1_lfb1
*&---------------------------------------------------------------------*
*&
Form SUB_GET_ADRC
*&---------------------------------------------------------------------*
*
This Subroutine is used to get Addresses data( ADRC Table)
*----------------------------------------------------------------------*
FORM SUB_GET_ADRC .

SELECT ADDRNUMBER
SORT1
SORT2
FROM ADRC
INTO TABLE T_ADRC
FOR ALL ENTRIES IN T_LFA1_LFB1
WHERE ADDRNUMBER = T_LFA1_LFB1-ADRNR.
ENDFORM.
" SUB_GET_ADRC
*&---------------------------------------------------------------------*
*&
Form sub_pop_output
*&---------------------------------------------------------------------*
*
This subroutine is used to display the output(Populating the output)
*----------------------------------------------------------------------*
FORM SUB_POP_OUTPUT .
LOOP AT T_LFA1_LFB1 INTO W_LFA1_LFB1.
W_OUTPUT-LIFNR
W_OUTPUT-NAME1
W_OUTPUT-NAME2
W_OUTPUT-ZAHLS

=
=
=
=

W_LFA1_LFB1-LIFNR.
W_LFA1_LFB1-NAME1.
W_LFA1_LFB1-NAME2.
W_LFA1_LFB1-ZAHLS.

CLEAR W_ADRC.
READ TABLE T_ADRC INTO W_ADRC WITH KEY ADDRNUMBER = W_LFA1_LFB1-ADRNR.
IF SY-SUBRC = 0.
W_OUTPUT-SORT1 = W_ADRC-SORT1.
W_OUTPUT-SORT2 = W_ADRC-SORT2.
ENDIF.
CASE W_LFA1_LFB1-BUKRS.
WHEN '1000'.
" Becos we should create 2 files---->
one is for toys, 2nd is for vit as per company code
APPEND W_OUTPUT TO T_TOYS.
WHEN '3000'.
( for vit)
APPEND W_OUTPUT TO T_VIT.

" Compnay codes-1000( for toys) and 3000

ENDCASE.
CLEAR W_OUTPUT.
ENDLOOP.
ENDFORM.
" sub_pop_output
*&---------------------------------------------------------------------*
*&
Form sub_send_data
*&---------------------------------------------------------------------*
*
(Outbound-Interface)
* This subroutine is used to send 2 files in the Application Level
*
- 1 for toys and other for vit
*----------------------------------------------------------------------*
FORM SUB_SEND_DATA .
DATA : L_LINE TYPE STRING.

IF T_TOYS IS NOT INITIAL.


" One file is
for Toys
OPEN DATASET P_TOYS FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF SY-SUBRC = 0.
LOOP AT T_TOYS INTO W_OUTPUT.
CONCATENATE '"' W_OUTPUT-SORT2
'"' W_OUTPUT-LIFNR
'"' W_OUTPUT-NAME1
'"' W_OUTPUT-NAME2
'"' W_OUTPUT-ZAHLS
'"' W_OUTPUT-SORT1
INTO L_LINE.
SEPARATED BY ','.

'"'
'"'
'"'
'"'
'"'
'"'

','
','
','
','
','
','

TRANSFER L_LINE TO P_TOYS.


ENDLOOP.
CLOSE DATASET P_TOYS.
IF SY-SUBRC = 0.
WRITE : /2 'File Created Successfully', 35 P_TOYS.
ENDIF.
ENDIF.
ENDIF.
IF T_VIT IS NOT INITIAL.
" One file is
for vit
OPEN DATASET P_VIT FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC = 0.
LOOP AT T_VIT INTO W_OUTPUT.
CONCATENATE W_OUTPUT-SORT2
W_OUTPUT-LIFNR
W_OUTPUT-NAME1
W_OUTPUT-NAME2
W_OUTPUT-ZAHLS
W_OUTPUT-SORT1
INTO L_LINE
SEPARATED BY ','.
TRANSFER L_LINE TO P_VIT.
ENDLOOP.
CLOSE DATASET P_VIT.
IF SY-SUBRC = 0.
WRITE : /2 'File Created Successfully', 35 P_VIT.
ENDIF.
ENDIF.
ENDIF.
ENDFORM.

" sub_send_data