Skip to Content

Below is the Source Code ::

FUNCTION ZASAT_PO_PDF_DISPLAY_RFC .
*”———————————————————————-
*”*”Local Interface:
*”  IMPORTING
*”     VALUE(IMP_PO) TYPE  EBELN
*”  EXPORTING
*”     VALUE(E_URL) TYPE  STRING
*”     VALUE(E_PO) TYPE  EBELN
*”———————————————————————-

DATA :
LV_FM_NAME            
TYPE RS38L_FNAM,
LS_OUTPUT_OPTIONS     
TYPE SSFCOMPOP,
LV_LANGUAGE           
TYPE TDSPRAS,
LS_CONTROL_PARAMETERS 
TYPE SSFCTRLOP,
LS_OUTPUT_DATA        
TYPE SSFCRESCL,
LV_PDF_LEN            
TYPE I,
LV_PDF_XSTRING        
TYPE XSTRING,
LT_LINES              
TYPE TABLE OF TLINE,
LV_DEVTYPE            
TYPE RSPOPTYPE,
LV_APP_TYPE           
TYPE STRING,
LV_GUID               
TYPE GUID_32,
LO_CACHED_RESPONSE    
TYPE REF TO IF_HTTP_RESPONSE,
LS_EKKO               
TYPE EKKO,
LS_EKPO               
TYPE EKPO,
LS_EKET               
TYPE EKET,
LS_KONV               
TYPE KONV,
LT_KONV               
TYPE TABLE OF KONV,
LT_EKKO               
TYPE TABLE OF EKKO,
LT_EKPO               
TYPE TABLE OF EKPO,
LT_EKET               
TYPE TABLE OF EKET,
LT_TSTOTF             
TYPE TSFOTF,
LS_PEKKO               
TYPE PEKKO,
LS_NAST                
TYPE NAST,
LV_FROM_MEM            
TYPE C,
LV_DRUVO               
TYPE DRUVO.

DATA : LS_TOA_DARA TYPE TOA_DARA,
TSFDARA
TYPE TSFDARA,
ARC_PARAMS
TYPE ARC_PARAMS,
SSFCTRLOP
TYPE SSFCTRLOP,
SWOTOBJID
TYPE SWOTOBJID,
M_SWOTOBJID
TYPE SWOTOBJID,
M1_SWOTOBJID
TYPE SWOTOBJID.

DATA : LT_EKEK TYPE TABLE OF EKEK,
LT_EKKN
TYPE TABLE OF EKKN,
LT_EKPA
TYPE TABLE OF EKPA,
LT_PEKPO
TYPE TABLE OF PEKPO,
LT_TKOMV
TYPE TABLE OF KOMV,
LT_KOMK
TYPE TABLE OF KOMK,
LT_NAST
TYPE TABLE OF NAST.
* LANGUAGE
LV_LANGUAGE = SY-LANGU.

TRANSLATE LV_LANGUAGE TO UPPER CASE.
LS_CONTROL_PARAMETERS-LANGU = LV_LANGUAGE.

* SET CONTROL PARAMETERS TO GET THE OUTPUT TEXT FORMAT (OTF) FROM SMART FORMS
LS_CONTROL_PARAMETERS-NO_DIALOG =
‘X’.
LS_CONTROL_PARAMETERS-GETOTF    =
‘X’.
LS_CONTROL_PARAMETERS-PREVIEW = SPACE.
“NO PREVIEW

* GET DEVICE TYPE FROM LANGUAGE
CALL FUNCTION ‘SSF_GET_DEVICE_TYPE’
EXPORTING
I_LANGUAGE             = LV_LANGUAGE
*     I_APPLICATION          = ‘SAPDEFAULT’
IMPORTING
E_DEVTYPE              = LV_DEVTYPE
EXCEPTIONS
NO_LANGUAGE            =
1
LANGUAGE_NOT_INSTALLED =
2
NO_DEVTYPE_FOUND       =
3
SYSTEM_ERROR           =
4
OTHERS                 = 5.

* SET DEVICE TYPE IN OUTPUT OPTIONS
LS_OUTPUT_OPTIONS-TDPRINTER = LV_DEVTYPE.
* SET RELEVANT OUTPUT OPTIONS
LS_OUTPUT_OPTIONS-TDNEWID  =
‘X’. “PRINT PARAMETERS,
LS_OUTPUT_OPTIONS-TDDELETE = SPACE.
“PRINT PARAMETERS

CALL FUNCTION ‘SSF_FUNCTION_MODULE_NAME’
EXPORTING
FORMNAME           =
‘ZBSG_MMPO_PO_CCI_CPY’  ” PO SMARTFORM NAME
IMPORTING
FM_NAME            = LV_FM_NAME
EXCEPTIONS
NO_FORM            =
1
NO_FUNCTION_MODULE =
2
OTHERS             = 3.

* DATA RETRIEVAL AND SUPPLYING IT TO SAMRTFORM FM

SELECT SINGLE * FROM EKKO INTO LS_EKKO WHERE EBELN = IMP_PO .

SELECT * FROM EKPO INTO TABLE LT_EKPO WHERE EBELN = IMP_PO.

SELECT * FROM EKET INTO TABLE LT_EKET WHERE EBELN = IMP_PO.

SELECT * FROM KONV INTO TABLE LT_KONV WHERE KNUMV = LS_EKKO-KNUMV.

SELECT SINGLE * FROM NAST INTO LS_NAST WHERE OBJKY = IMP_PO AND KSCHL = ‘ZNE1’ .

SELECT * FROM EKEK INTO TABLE LT_EKEK WHERE EBELN = IMP_PO.

CALL FUNCTION LV_FM_NAME
EXPORTING
ARCHIVE_INDEX              = LS_TOA_DARA
ARCHIVE_INDEX_TAB          = TSFDARA
ARCHIVE_PARAMETERS         = ARC_PARAMS
CONTROL_PARAMETERS         = LS_CONTROL_PARAMETERS
MAIL_APPL_OBJ              = SWOTOBJID
MAIL_RECIPIENT             = M_SWOTOBJID
MAIL_SENDER                = M1_SWOTOBJID
OUTPUT_OPTIONS             = LS_OUTPUT_OPTIONS
USER_SETTINGS              = SPACE
IS_EKKO                    = LS_EKKO
IS_PEKKO                   = LS_PEKKO
IS_NAST                    = LS_NAST
*   IV_FROM_MEM                =
*    IV_DRUVO                   = LS_D
IMPORTING
*   DOCUMENT_OUTPUT_INFO       =
JOB_OUTPUT_INFO            = LS_OUTPUT_DATA
*   JOB_OUTPUT_OPTIONS         =
TABLES
IT_EKPO                    = LT_EKPO
IT_EKPA                    = LT_EKPA
IT_PEKPO                   = LT_PEKPO
IT_EKET                    = LT_EKET
IT_TKOMV                   = LT_TKOMV
IT_EKKN                    = LT_EKKN
IT_EKEK                    = LT_EKEK
IT_KOMK                    = LT_KOMK
IT_NAST                    = LT_NAST
IT_KONV                    = LT_KONV
EXCEPTIONS
FORMATTING_ERROR           =
1
INTERNAL_ERROR             =
2
SEND_ERROR                 =
3
USER_CANCELED              =
4
OTHERS                     = 5
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
**

APPEND LINES OF LS_OUTPUT_DATA-OTFDATA[] TO LT_TSTOTF[].

* CONVERT TO OTF
CALL FUNCTION ‘CONVERT_OTF’
EXPORTING
FORMAT                = ‘PDF’
IMPORTING
BIN_FILESIZE          = LV_PDF_LEN
BIN_FILE              = LV_PDF_XSTRING      
” BINARY FILE
TABLES
OTF                   = LT_TSTOTF
LINES                 = LT_LINES
EXCEPTIONS
ERR_MAX_LINEWIDTH     =
1
ERR_FORMAT            =
2
ERR_CONV_NOT_POSSIBLE =
3
ERR_BAD_OTF           =
4
OTHERS                = 5.
IF SY-SUBRC <> 0.
*   ERROR HANDLING
*    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CREATE OBJECT LO_CACHED_RESPONSE
TYPE
CL_HTTP_RESPONSE
EXPORTING
ADD_C_MSG =
1.

****SET THE DATA AND THE HEADERS
LO_CACHED_RESPONSE->SET_DATA( LV_PDF_XSTRING ).
LV_APP_TYPE =
‘.PDF’.

LO_CACHED_RESPONSE->SET_HEADER_FIELD( NAME  = IF_HTTP_HEADER_FIELDS=>CONTENT_TYPE
VALUE = LV_APP_TYPE ).
****SET THE RESPONSE STATUS
LO_CACHED_RESPONSE->SET_STATUS(
CODE = 200 REASON = ‘OK’ ).

****SET THE CACHE TIMEOUT – 60 SECONDS – WE ONLY NEED THIS IN THE CACHE
****LONG ENOUGH TO BUILD THE PAGE
LO_CACHED_RESPONSE->SERVER_CACHE_EXPIRE_REL( EXPIRES_REL =
60 ).

****CREATE A UNIQUE URL FOR THE OBJECT AND EXPORT URL
CALL FUNCTION ‘GUID_CREATE’
IMPORTING
EV_GUID_32 = LV_GUID.
CONCATENATE  ‘/sap/public’ ‘/’ LV_GUID ‘.’ ‘PDF’ INTO E_URL.
****CACHE THE URL
CL_HTTP_SERVER=>SERVER_CACHE_UPLOAD( URL      = E_URL
RESPONSE = LO_CACHED_RESPONSE ).

ENDFUNCTION.

Create the Gateway Service in SEGW T-Code

After Importing the parameters from RFC, need to mapping the Service using READ Operation.

  1. Then, We have to Redefine the SETGET_ENTITY_SET Method otherwise it will give errorà for that need to follow the below screen shot

Using Service Maintenance we can generate the URL

EX : OUTPUT

SELECTION SCREEN: PO Number

URL:

http:8000/sap/opu/odata/sap/ZASAT_PO_PDF_SRV/POPDFSet(‘4500017980’)

RESULT is

EX :  Output  in XML Format is

<d:ImpPo>4500017980</d:ImpPo>

<d:EUrl>/sap/public/0019B9CD3BE01ED49D901F7B38C5BAF1.PDF</d:EUrl>

Note : We have to redirect the EUrl again into the HTML to get the PDF.

Next URL : http://ecc:8000/sap/public/0019B9CD3BE01ED49DC30F93206BBAF1.PDF

To report this post you need to login first.

6 Comments

You must be Logged on to comment or reply to a post.

  1. Ron Sargeant

    Hi Shanthan,

    I’m not sure exactly what this has to do with OData other than this being shoe-horned into SEGW. Your source code is typically what might be attached to an ICF node so that this can be done over HTTP –  there is not much “OData-ness” about it.

    Attaching a temporary GUID makes the URI transient, it cannot be recalled by the same ID if a cache is invalidated, i.e. there is no canonical URI. With SAP OData this tends to be a problem for some use cases.

    If this were a proper OData-compliant entity, the PDF URL should be defined as a media link to a permanent URI for the purchase order in PDF form.

    Finally the title ‘PDF Display using OData services’ is misleading. The OData service is not what renders the PDF binary for display, it is the consumer, e.g. browser plug-in.

    Regards

    Ron.

    (0) 
    1. Shanthan Reddy Post author

      Hi Ron,

      actually the requirement is to check the PO number with in the Http and send to approvers using Email service ( displaying all the PO’s are in a table manner using http with all other functionality’s )

      we are getting all the data from the back end, and if the user want to check the PO and view it as in PDF format and save it desktop we can do it in this way.

      i have not given clear explanation in the above blog..

      what we are displaying in pdf format, is already developed in SAP as a smartform..

      (0) 

Leave a Reply